/**
 * @file Describe the file Created by Administrator on 2015/5/20.
 */

var ConstantsBase = new Constants();
function BaseUtil() {
    this.updateDateFormateYMDHMS = function (eleValue) {
        var str = '';
        var tools = {
            addZero: function (value) {
                return value < 10 ? '0' + value : value;
            }
        };

        if (Number(eleValue) === 0) {
            return str = '--';
        } else {
            var time = new Date(Number(eleValue) * 1000);
            var year = time.getFullYear();
            var month = tools.addZero(time.getMonth() + 1);
            var day = tools.addZero(time.getDate());
            var hours = tools.addZero(time.getHours());
            var minutes = tools.addZero(time.getMinutes());
            var seconds = tools.addZero(time.getSeconds());
            str = year + '/' + month + '/' + day + ' ' + hours + ':' + minutes + ':' + seconds;
            return str;
        }

    };

    this.updateDateFormate = function (eleValue) {
        var str = '';
        var tools = {
            addZero: function (value) {
                return value < 10 ? '0' + value : value;
            }
        };

        if (Number(eleValue) === 0) {
            return str = '--';
        } else {
            var time = new Date(Number(eleValue) * 1000);
            var year = time.getFullYear();
            var month = tools.addZero(time.getMonth() + 1);
            var day = tools.addZero(time.getDate());
            str = year + '/' + month + '/' + day;
            return str;
        }

    };

    this.money = function (ele) {
        if (ele === undefined || ele === null || Number(ele) === 0 || String(ele) === '') {
            return '0';
        } else {
            var str = (ele / 100).toFixed(2) + '';
            var intSum = str.substring(0, str.indexOf('.')).replace(/\B(?=(?:\d{3})+$)/g, ',');// 取到整数部分
            var dot = str.substring(str.length, str.indexOf('.'));// 取到小数部分
            var ret = intSum + dot;
            return ret;
        }

    };

    this.orderTotalOtherFormate = function (eleValue) {
        var result = eleValue;
        if (eleValue === null || eleValue === undefined) {
            result = '--';
        }

        if (String(eleValue) === '') {
            result = '--';
        }

        if (String(eleValue) === 'N') {
            result = '--';
        }
        return result;
    };

//    this.checkDate = function () {
//        var startdate = $('.startDate').val();
//        var endate = $('.endDate').val();
//        if ((startdate == null || startdate == '' || startdate == undefined)
//                || (endate == null || endate == '' || endate == undefined)) {
//            alert('时间不能为空！');
//            return false;
//        }
//        if (startdate != null && startdate != '' && startdate != undefined) {
//            if (endate != null && endate != '' && endate != undefined) {
//                if (startdate.substring(0, 7) != endate.substring(0, 7)) {
//                    alert('时间必须为同年同月！');
//                    return false;
//                }
//                if (endate < startdate) {
//                    alert('开始时间不能大于结束时间！');
//                    return false;
//                }
//            }
//        }
//        return true;
//    }

    this.orderTypeFormate = function (eleValue) {
        var result = '--';
        if (Number(eleValue) === ConstantsBase.getOrderTypeConstant('ORDER_REPAY')) {
            result = '还款订单';
        } else if (Number(eleValue) === ConstantsBase.getOrderTypeConstant('ORDER_LOAN')) {
            result = '贷款订单';
        } else if (Number(eleValue) === ConstantsBase.getOrderTypeConstant('ORDER_BIZ_PAY')) {
            result = '放款订单(对公)';
        } else if (Number(eleValue) === ConstantsBase.getOrderTypeConstant('ORDER_BIZ_REFUND')) {
            result = '退款订单(对公)';
        }
        return result;
    };

    this.orderTypeFormateSwitch = function (eleValue, accounType) {
        var result = '--';

        if (accounType !== null && accounType !== undefined) {
            if (String(accounType) !== '' && Number(accounType) === 1) {
                if (Number(eleValue) === ConstantsBase.getOrderTypeConstant('ORDER_REPAY')) {
                    result = '还款订单';
                } else if (Number(eleValue) === ConstantsBase.getOrderTypeConstant('ORDER_LOAN')) {
                    result = '贷款订单';
                } else if (Number(eleValue) === ConstantsBase.getOrderTypeConstant('ORDER_BIZ_PAY')) {
                    result = '放款订单(对公)';
                } else if (Number(eleValue) === ConstantsBase.getOrderTypeConstant('ORDER_BIZ_REFUND')) {
                    result = '退款订单(对公)';
                }
            }
        }

        return result;
    };

    this.orderStatusFormate = function (eleValue) {
        var result = '--';
        if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('PAY_INIT')) {
            result = '--';
        } else if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('PAY_WAIT')) {
            result = '验证通过等待支付';
        } else if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('CHECK_FAIL')) {
            result = '验证失败';
        } else if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('PAYING')) {
            result = '正在支付中';
        } else if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('PAY_SUCCESS')) {
            result = '支付明确成功';
        } else if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('PAY_FAIL')) {
            result = '支付明确失败';
        } else if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('PAY_COMPLETE')) {
            result = '订单完成';
        } else if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('ORDER_CANCEL')) {
            result = '订单取消';
        } else if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('ROLLBACKING')) {
            result = '回滚中';
        } else if (Number(eleValue) === ConstantsBase.getOrderStatusConstant('ROLLBACK_COMPLETE')) {
            result = '回滚完成';
        }
        return result;
    };

    this.settleStatusFormate = function (eleValue) {
        var result = '--';
        if (Number(eleValue) === 0) {
            result = '未对账';
        } else if (Number(eleValue) === 1) {
            result = '已对账';
        }
        return result;
    };

    this.loanTypeFormate = function (eleValue) {
        var result = '--';
        if (Number(eleValue) === ConstantsBase.getLoanTypeConstant('LOAN_TO_CUSTOMER')) {
            result = '贷款到用户';
        } else if (Number(eleValue) === ConstantsBase.getLoanTypeConstant('LOAN_TO_BIZ')) {
            result = '贷款到商户';
        }
        return result;
    };

    this.payWayFormate = function (eleValue) {
        var result = '--';
        if (Number(eleValue) === ConstantsBase.getPayWayConstant('PAY_TO_ACCOUNT')) {
            result = '放款到账户';
        } else if (Number(eleValue) === ConstantsBase.getPayWayConstant('PAY_TO_BANKCARD')) {
            result = '放款到银行卡';
        }
        return result;
    };

    this.payChannelFormate = function (eleValue) {
        var result = '--';
        if (Number(eleValue) === ConstantsBase.getPayChannelConstant('CHANNEL_BAIDU_CONVERGE')) {
            result = '聚合收银台';
        } else if (Number(eleValue) === ConstantsBase.getPayChannelConstant('CHANNEL_BAIDU_TO_ACCOUNT')) {
            result = '钱包到账户';
        } else if (Number(eleValue) === ConstantsBase.getPayChannelConstant('CHANNEL_BAIDU_TO_BANKCARD')) {
            result = '钱包到银行卡';
        }
        return result;
    };

    this.payChannelFormateSwitch = function (eleValue, accounType) {
        var result = '--';

        if (accounType !== null && accounType !== undefined && String(accounType) !== '' && Number(accounType) > 1) {
            if (Number(eleValue) === ConstantsBase.getPayChannelConstant('CHANNEL_BAIDU_CONVERGE')) {
                result = '聚合收银台';
            } else if (Number(eleValue) === ConstantsBase.getPayChannelConstant('CHANNEL_BAIDU_TO_ACCOUNT')) {
                result = '付款到钱包';
            } else if (Number(eleValue) === ConstantsBase.getPayChannelConstant('CHANNEL_BAIDU_TO_BANKCARD')) {
                result = '钱包到银行卡';
                // result = '付款到钱包';
            }

        }
        return result;
    };

    this.coreChannelFormate = function (eleValue) {
        var result = '--';
        if (Number(eleValue) === ConstantsBase.getCoreChannelConstant('CORE_NONE')) {
            result = '核心无关';
        } else if (Number(eleValue) === ConstantsBase.getCoreChannelConstant('CORE_REPAY')) {
            result = '核心还款';
        } else if (Number(eleValue) === ConstantsBase.getCoreChannelConstant('CORE_CREDIT')) {
            result = '消费度零钱';
        } else if (Number(eleValue) === ConstantsBase.getCoreChannelConstant('CORE_CREDIT_PLAN')) {
            result = '消费分期计划';
        }
        return result;
    };

    this.bizChannelFormate = function (eleValue) {
        var result = '--';
        if (Number(eleValue) === ConstantsBase.getBizChannelConstant('BIZ_UMONEY')) {
            result = '有钱';
        } else if (Number(eleValue) === ConstantsBase.getBizChannelConstant('BIZ_BAR')) {
            result = '贴吧';
        } else if (Number(eleValue) === ConstantsBase.getBizChannelConstant('BIZ_CHUANKE')) {
            result = '传课';
        }
        return result;
    };

    this.orderStatusMyFormate = function (eleValue) {
        var result = '--';
        switch (eleValue) {
            case ConstantsBase.getOrderStatusConstant('PAY_INIT'):
                result = '初始未生效';
                break;
            case ConstantsBase.getOrderStatusConstant('PAY_WAIT'):
                result = '验证通过等待支付';
                break;
            case ConstantsBase.getOrderStatusConstant('CHECK_FAIL'):
                result = '验证失败';
                break;
            case ConstantsBase.getOrderStatusConstant('PAYING'):
                result = '正在支付中';
                break;
            case ConstantsBase.getOrderStatusConstant('PAY_SUCCESS'):
                result = '支付明确成功';
                break;
            case ConstantsBase.getOrderStatusConstant('PAY_FAIL'):
                result = '支付明确失败';
                break;
            case ConstantsBase.getOrderStatusConstant('PAY_COMPLETE'):
                result = '订单完成';
                break;
            case ConstantsBase.getOrderStatusConstant('ORDER_CANCEL'):
                result = '订单取消';
                break;
        }
        return result;
    };

    this.resultError = function (data) {
        if (data !== null && data !== undefined) {
            if (data.responseJSON !== undefined && data.responseJSON.msg !== undefined) {
                alert(data.responseJSON.msg);
            } else {
                if (data.status !== null && data.status !== undefined) {
                    if (Number(data.status) > 0 && data.msg !== null && data.msg !== undefined) {
                        alert(data.msg);
                    } else {
                        alert('操作异常。');
                    }
                }
            }
        } else {
            alert('操作异常。');
        }
    };

    this.resultSuccess = function (data) {
        if (data !== null && data !== undefined) {
            if (data.status !== null && data.status !== undefined) {
                if (Number(data.status) > 0 && data.msg !== null && data.msg !== undefined) {
                    alert(data.msg);
                    return;
                }
            }
        }
    };

}